<script type="text/javascript">
    $(document).ready(function () {
        var json;
        var responseString;
        // NotyManager initialization

        window.NotyManager = new $.NotyManager($('#notifications'), {
            bubble: { // bubble positioning settings
                top: 2,
                left: -2,
                showZero: false
            },
            max: 30, // max bubble count
            container: $('#notification-list'), // this this the notification container
            wrapper: '<div/>', // this is the wrapper of the a single notification
            emptyHTML: '<div id="notypop" class="no-notification">Loading...</div>',
            callback: {
                onOpen: function () {
                    if (responseString.substring(0, 1) == "0") {
                        $("div.notymanager-empty-html").text("There are no notification here.");
                    }
                    //                 	if($('.no-notification').is(':visible')){
                    //                 		$('#menuShowAllNotification').hide();
                    //                 	}else{
                    //                 		$('#menuShowAllNotification').show();
                    //                 	}
                    // NotyManager instance accessible with this variable in this scope
                    if (typeof console != 'undefined' && console.log)
                        console.log('opened', this);
                    if (!json == "") {
                        $.ajax({
                            url: "${pageContext.request.contextPath}/account/update-status-all-noty.html",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            data: json, //Stringified Json Object
                            success: function (resposeJsonObject) {}
                        });
                    }
                },
                onClose: function () {
                    // NotyManager instance accessible with this variable in this scope
                    if (responseString.substring(0, 1) == "0") {
                        $("div.notymanager-empty-html").text("There are no notification here.");
                    }
                    if (typeof console != 'undefined' && console.log) {
                        NotyManager.decrease(NotyManager.getNotificationCount());
                        console.log('closed', this);
                    }
                }
            },

            // Below settings for the using open source Noty plugin
            useNoty: true, // if true notifications also appears on the screen
            noty: { // this settings used when if useNoty is `true`
                layout: 'bottomLeft',
                timeout: 10000,
                closeWith: ['button']
            }
        });

        $.atmosphere.subscribe(
            "${pageContext.request.contextPath}/notification.html",
            callback,
            $.atmosphere.request = {
                transport: "websocket"
            });

        //Function to be invoked when there is a response from the server
        function callback(response) {
            //         	console.log(response.responseBody);
            responseString = response.responseBody;
            if ((responseString == "0[]#$@#[]") || ($("#bottomWhenDontHaveNoty").length > 0)) {
                NotyManager.setCount(0);
                NotyManager.clearNotifications();
            }
            console.log("HERE:" + responseString);

            // first get notification or not
            var typeData = response.responseBody.substring(0, 1);

            if (typeData == 0) {
                // response in format 0[SUB_NOTIFICATION]#$@#[TASK_NOTIFICATION]
                // save json for update notification status: isRead
                json = response.responseBody;
				
                // first get of all notification: sub and task noty
                var arr = response.responseBody.substring(1).split("#$@#");
                
                var flightNotification = JSON.parse(arr[0]);
                var taskNotification = JSON.parse(arr[1]);
				
                console.log("0[SUB_NOTIFICATION]#$@#[TASK_NOTIFICATION]" 
                		+ " SUB LENGTH: " + flightNotification.length
                		+ " TASK LENGTH: " + taskNotification.length);
                
                // get sub notification
                $.each(flightNotification, function (index, notification) {
                    switch (notification.flightChangeType) {
                    case (0):
                        if (notification.isRead == 0) {
                            var notificationPrice = '<div class="activity-item noty-unread" name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-money text-warning"></i> <div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"><font name="priceNotification">' + notification.oldPrice + '</font><font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"><font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> <span>' + notification.driftTime + '</span> </div></div>';
                        } else {
                            var notificationPrice = '<div class="activity-item" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-money text-warning"></i> <div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"><font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"><font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> <span>' + notification.driftTime + '</span> </div></div>';
                        }
                        if (notification.status == 0) {
                            NotyManager.info(notificationPrice, {
                                useNoty: false,
                                increase: true
                            });
                        } else {
                            NotyManager.info(notificationPrice, {
                                useNoty: false,
                                increase: false
                            });
                        }
                        break;
                    case (1):
                        if (notification.isRead == 0) {
                            var notificationSchedule = '<div class="activity-item noty-unread"  name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-clock-o text-warning"></i><div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed schedule' + ' <span>' + notification.driftTime + '</span></div></div>';
                        } else {
                            var notificationSchedule = '<div class="activity-item" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-clock-o text-warning"></i><div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed schedule' + ' <span>' + notification.driftTime + '</span></div></div>';
                        }
                        if (notification.status == 0) {
                            NotyManager.info(notificationSchedule, {
                                useNoty: false,
                                increase: true
                            });
                        } else {
                            NotyManager.info(notificationSchedule, {
                                useNoty: false,
                                increase: false
                            });
                        }
                        break;
                    case (2):
                        if (notification.isRead == 0) {
                            var notificationBothType = '<div class="activity-item noty-unread" name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-money text-warning"></i> <div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"><font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"><font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + 'and schedule</font> <span>' + notification.driftTime + '</span> </div></div>';
                        } else {
                            var notificationBothType = '<div class="activity-item" name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-money text-warning"></i> <div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"><font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"><font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + 'and schedule</font> <span>' + notification.driftTime + '</span> </div></div>';
                        }
                        if (notification.status == 0) {
                            NotyManager.info(notificationBothType, {
                                useNoty: false,
                                increase: true
                            });
                        } else {
                            NotyManager.info(notificationBothType, {
                                useNoty: false,
                                increase: false
                            });
                        }
                        break;
                    }
                });
                
             // get task notification
             $.each(taskNotification, function (index, notification) {
             	if (notification.isRead == 0) {
                     var notificationTask = '<div class="activity-item noty-unread" name="notyTopbar" style="cursor:pointer" onclick="linkToTask(\'' + notification.taskId + '\',\'' + notification.id + '\',this)"><i class="fa fa-tasks text-warning"></i> <div class="activity">Task <a id="flight-route">' + notification.taskName + '</a> has found flights: <a id="flight-departure-time">' + notification.taskInfo + '</a><span>' + notification.driffTime + '</span></div></div>';
                 } else {
                     var notificationTask = '<div class="activity-item" name="notyTopbar" style="cursor:pointer" onclick="linkToTask(\'' + notification.taskId + '\',\'' + notification.id + '\',this)"><i class="fa fa-tasks text-warning"></i> <div class="activity">Task <a id="flight-route">' + notification.taskName + '</a> has found flights: <a id="flight-departure-time">' + notification.taskInfo + '</a><span>' + notification.driffTime + '</span></div></div>';
                 }
                 if (notification.status == 0) {
                     NotyManager.info(notificationTask, {
                         useNoty: false,
                         increase: true
                     });
                 } else {
                     NotyManager.info(notificationTask, {
                         useNoty: false,
                         increase: false
                     });
                 }
             });
                
            } else
            if (typeData == 1) {
                // new notification
                // response in format 10[SUB_NOTIFICATION] or 11[TASK_NOTIFICATION]
                var jsonString = response.responseBody.substring(2);

                // save jsonString for update notification status: isRead
                json = response.responseBody;

                // first get notification or not
                var isTaskNotification = response.responseBody.substring(1, 2);

                if (isTaskNotification == 0) {
                	var flightNotification = JSON.parse(jsonString);
                    // new notification of subscribed flight
                	$.each(flightNotification, function (index, notification) {
                        switch (notification.flightChangeType) {
                        case (0):
                            var notificationPrice = '<div class="activity-item noty-unread"  name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-money text-warning"></i> <div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"> <font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"> <font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> <span>' + notification.driftTime + '</span> </div></div>';
                            NotyManager.info(notificationPrice);
                            if ($('#listNotificationCenter').length > 0) {
                                $('div#listNotificationCenter').prepend('<form action="../subscribe/link-to-subscribe.html" method="post" id="notyform-' + notification.flightId + '"><div class="row" id="divNoty"><input type="hidden" value="' + notification.flightId + '" name="flightId"/><div class="border-blue notification-center-message-background-unread columns" name="notificationElement"><br><div class="small-1 un-padding columns"><i class="fa fa-money"></i></div><div class="small-14 un-padding columns"><span class="notification-center-message" onclick="submitToSubscribe(\'' + notification.id + '\',\'' + notification.flightId + '\',this)"><a>Flight <strong>' + notification.flightRoute + '</strong> depart at ' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + ' has change price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"> <font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"> <font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font></a></span><br><span class="notification-center-time">' + notification.driftTime + '</span></div><div class="small-1 un-padding columns"><a href="#"><i class="fa fa-trash-o" onclick="requestToDeleteOne(\'' + notification.id + '\',this)"></i></a></div></div></div></form>');
                            }
                            if ($("#bottomWhenDontHaveNoty").length > 0) {
                                $("#bottomWhenDontHaveNoty").remove();
                                $("#notyCenterBottom").append('<div id="bottomWhenHaveNoty"><div class="small-8 columns"><span class="small update-profile button expand" onclick="markAllAsRead()">Mark all as read</span></div><div class="small-8 columns"><span class="small update-profile button expand" onclick="requestToDeleteAll()">Delete all</span></div></div>');
                            }
                            if ($("#bottomWhenHaveNoty").length > 0) {
                                $("#notyCenterBottom").addClass("border-blue");
                                $("#borderOfPanel").addClass("profile-panel");
                                $("#borderOfPanel").addClass("background-secondary");
                                $("#borderOfPanel").css('text-align', '');
                            }

                            break;
                        case (1):
                            var notificationSchedule = '<div class="activity-item noty-unread"  name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-clock-o text-warning"></i><div class="activity">Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed schedule' + ' <span>' + notification.driftTime + '</span></div></div>';
                            NotyManager.info(notificationSchedule);
                            if ($('#listNotificationCenter').length > 0) {
                                $('div#listNotificationCenter').prepend('<form action="../subscribe/link-to-subscribe.html" method="post" id="notyform-' + notification.flightId + '"><div class="row" id="divNoty"><input type="hidden" value="' + notification.flightId + '" name="flightId"/><div class="border-blue notification-center-message-background-unread columns" name="notificationElement"><br><div class="small-1 un-padding columns"><i class="fa fa-clock-o"></i></div><div class="small-14 un-padding columns"><span class="notification-center-message" onclick="submitToSubscribe(\'' + notification.id + '\',\'' + notification.flightId + '\',this)"><a>Flight <strong>' + notification.flightRoute + '</strong> depart at ' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + ' has change schedule </a></span><br><span class="notification-center-time">' + notification.driftTime + '</span></div><div class="small-1 un-padding columns"><a href="#"><i class="fa fa-trash-o" onclick="requestToDeleteOne(\'' + notification.id + '\',this)"></i></a></div></div></div></form>');
                            }
                            if ($("#bottomWhenDontHaveNoty").length > 0) {
                                $("#bottomWhenDontHaveNoty").remove();
                                $("#notyCenterBottom").append('<div id="bottomWhenHaveNoty"><div class="small-8 columns"><span class="small update-profile button expand" onclick="markAllAsRead()">Mark all as read</span></div><div class="small-8 columns"><span class="small update-profile button expand" onclick="requestToDeleteAll()">Delete all</span></div></div>');
                            }
                            if ($("#bottomWhenHaveNoty").length > 0) {
                                $("#notyCenterBottom").addClass("border-blue");
                                $("#borderOfPanel").addClass("profile-panel");
                                $("#borderOfPanel").addClass("background-secondary");
                                $("#borderOfPanel").css('text-align', '');


                            }
                            break;
                        case (2):
                            var notificationBothType = '<div class="activity-item noty-unread"  name="notyTopbar" style="cursor:pointer"  onclick="linkToSubscribe(\'' + notification.flightId + '\',\'' + notification.id + '\',this)"><i class="fa fa-tags text-warning"></i><div class="activity"> Flight <a id="flight-route">' + notification.flightRoute + '</a> depart at <a id="flight-departure-time">' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + '</a> has changed price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"> <font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"> <font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> and schedule' + ' <span>' + notification.driftTime + '</span></div>';
                            NotyManager.info(notificationBothType);
                            if ($('#listNotificationCenter').length > 0) {
                                $('div#listNotificationCenter').prepend('<form action="../subscribe/link-to-subscribe.html" method="post" id="notyform-' + notification.flightId + '"><div class="row" id="divNoty"><input type="hidden" value="' + notification.flightId + '" name="flightId"/><div class="border-blue notification-center-message-background-unread columns" name="notificationElement"><br><div class="small-1 un-padding columns"><i class="fa fa-money"></i></div><div class="small-14 un-padding columns"><span class="notification-center-message" onclick="submitToSubscribe(\'' + notification.id + '\',\'' + notification.flightId + '\',this)"><a>Flight <strong>' + notification.flightRoute + '</strong> depart at ' + notification.flightDepartureTime.substring(notification.flightDepartureTime.indexOf(" "), notification.flightDepartureTime.length) + ' ' + notification.flightDepartureTime.substring(0, notification.flightDepartureTime.indexOf(" ")) + ' has change price from <input name="inputHiddenNotification" type="hidden" value="' + notification.oldPrice + '"> <font name="priceNotification">' + notification.oldPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> to <input name="inputHiddenNotification" type="hidden" value="' + notification.newPrice + '"> <font name="priceNotification">' + notification.newPrice + '</font> <font name="codeCurrencyNotification">' + notification.currencyCode + '</font> and schedule </a></span><br><span class="notification-center-time">' + notification.driftTime + '</span></div><div class="small-1 un-padding columns"><a href="#"><i class="fa fa-trash-o" onclick="requestToDeleteOne(\'' + notification.id + '\',this)"></i></a></div></div></div></form>');
                            }
                            if ($("#bottomWhenDontHaveNoty").length > 0) {
                                $("#bottomWhenDontHaveNoty").remove();
                                $("#notyCenterBottom").append('<div id="bottomWhenHaveNoty"><div class="small-8 columns"><span class="small update-profile button expand" onclick="markAllAsRead()">Mark all as read</span></div><div class="small-8 columns"><span class="small update-profile button expand" onclick="requestToDeleteAll()">Delete all</span></div></div>');
                            }
                            if ($("#bottomWhenHaveNoty").length > 0) {
                                $("#notyCenterBottom").addClass("border-blue");
                                $("#borderOfPanel").addClass("profile-panel");
                                $("#borderOfPanel").addClass("background-secondary");
                                $("#borderOfPanel").css('text-align', '');


                            }
                            break;
                        }
                    });
                } else
                if (isTaskNotification == 1) {
                	var taskNotification = JSON.parse(jsonString);
                    // new notification of task
                	$.each(taskNotification, function (index, notification) {
                     	if (notification.isRead == 0) {
                             var notificationTask = '<div class="activity-item noty-unread" name="notyTopbar" style="cursor:pointer" onclick="linkToTask(\'' + notification.taskId + '\',\'' + notification.id + '\',this)"><i class="fa fa-tasks text-warning"></i> <div class="activity">Task <a id="flight-route">' + notification.taskName + '</a> has found flights: <a id="flight-departure-time">' + notification.taskInfo + '</a><span>' + notification.driffTime + '</span></div></div>';
                         } else {
                             var notificationTask = '<div class="activity-item" name="notyTopbar" style="cursor:pointer" onclick="linkToTask(\'' + notification.taskId + '\',\'' + notification.id + '\',this)"><i class="fa fa-tasks text-warning"></i> <div class="activity">Task <a id="flight-route">' + notification.taskName + '</a> has found flights: <a id="flight-departure-time">' + notification.taskInfo + '</a><span>' + notification.driffTime + '</span></div></div>';
                         }
                     	
                     	NotyManager.info(notificationTask);
                     	
                     });
                }
            }
            changePriceNotification();
        }
    });
</script>

<script type="text/javascript">
    function linkToSubscribe(flightId, notificationId, divTag) {
        showLoading();
        $('#inputNotyHidden').attr("value", flightId);
        $(divTag).removeClass("noty-unread");
        $.ajax({
            url: "${pageContext.request.contextPath}/account/mark-noty-read.html",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: notificationId, //Stringified Json Object
            success: function (response) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/account/check-subscribe-flight-exist.html",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data: flightId, //Stringified Json Object
                    success: function (response) {
                        if (response.length > 0) {
                            $('#formLinktoSubscribe').submit();
                        } else {
                            generate('error', "The subscribed flight has been deleted");
                        }
                        unShowLoading();
                    }
                });
            }
        });
    }
</script>

<script type="text/javascript">
    function linkToTask(taskId, notificationId, divTag) {
        $(divTag).removeClass("noty-unread");
        $.ajax({
            url: "${pageContext.request.contextPath}/account/mark-noty-read-task.html",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: notificationId, //Stringified Json Object
            success: function (response) {
            	console.log("Success set status " + notificationId);
            	$.ajax({
                    url: "${pageContext.request.contextPath}/account/check-task-exist.html",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data: taskId, //Stringified Json Object
                    success: function (response) {
                    	console.log("Success check task exits: " + response);
                        if (response.length > 0) {
                            // go to task list page
                        	window.location.href = '${pageContext.request.contextPath}/task/list.html';
                        } else {
                            generate('error', "The task has been deleted");
                        }
                    }
                });
            }
        });
    }
</script>
